/*
* $Id: TableItem.cpp 111 2010-07-01 15:26:44Z volok-aleksej@yandex.ru $
*
* Copyright 2009 by Volokitin Alexey
* All rights reserved
*
*/
#include "Common/include.h"
#include "TableStructs.h"
#include "TableItem.h"

CItemTable::CItemTable(COLORREF color)
: m_pos(0, 0), m_colorItem(color){}
CItemTable::~CItemTable(){}

void CItemTable::Paint(CDC* dc){
	CBrush brush;
	brush.CreateSolidBrush(m_colorItem);
	dc->FillRect(CRect(m_pos, m_size), &brush);
	CPen pen;
	pen.CreatePen(PS_SOLID, 1, RGB(0, 0, 0));
	HGDIOBJ penOld = dc->SelectObject(pen);
	dc->MoveTo(m_pos.x, m_pos.y);
	dc->LineTo(m_pos.x + m_size.cx, m_pos.y);
	dc->LineTo(m_pos.x + m_size.cx, m_pos.y + m_size.cy);
	dc->LineTo(m_pos.x, m_pos.y + m_size.cy);
	dc->LineTo(m_pos.x, m_pos.y);
	dc->SelectObject(penOld);
	pen.DeleteObject();
	brush.DeleteObject();
	CFont* pFont = CCommonFunction::GetFont(_T("Arial"), sizeFont, TRUE, FALSE);
	HGDIOBJ fontOld = dc->SelectObject(pFont);
	dc->SetBkMode(TRANSPARENT);
	tableItem *item = dynamic_cast<tableItem*>(this);
	dc->DrawText(item->m_strValue.c_str(), CRect(m_pos, m_size), DT_CENTER | DT_WORDBREAK);
	dc->SelectObject(fontOld);
	pFont->DeleteObject();
	delete pFont;
}
CSize CItemTable::GetSize(){
	return m_size;
}

CSize CItemTable::GetDefaultSize(int cx){
	tableItem *item = dynamic_cast<tableItem*>(this);
	CFont* pFont = CCommonFunction::GetFont(_T("Arial"), sizeFont, TRUE, FALSE);
	CSize size = CCommonFunction::GetSizeYText(item->m_strValue, cx, pFont);
	pFont->DeleteObject();
	delete pFont;
	return size;
}

CPoint CItemTable::GetPos(){
	return m_pos;
}

void CItemTable::SetColor(COLORREF color){
	m_colorItem = color;
}